In above code I declared array size 2 that means we can store only 2 string values in array.
ArrayList:
1. ArrayList can store any type of items\elements.
2. ArrayList grows automatically and you don't need to specify size.
3. Items of ArrayList need to be cast to appropriate data type while retrieving.
Declaration of ArrayList
ArrayList strarr = new ArrayList(); strarr.Add("welcome"); // Add string values strarr.Add(10); // Add integer values strarr.Add(10.05); // Add float value
If you observe above code I haven’t mentioned any size in array list we can add all the required data there is no size limit and we will use add method to bind values to array list.
Liked By
Write Answer
what is difference between Array and ArrayList?
Join MindStick Community
You have need login or register for voting of answers or question.
Niraj Kumar Mishra
28-Aug-2017Array:
1. Array is strongly typed. This means that an array can store only specific type of items\elements.
2. Array stores fixed number of elements. Size of an Array must be specified at the time of initialization.
3. No need to cast elements of an array while retrieving because it is strongly type and stores specific type of items only.
Declaration of Array
In above code I declared array size 2 that means we can store only 2 string values in array.
ArrayList:
1. ArrayList can store any type of items\elements.
2. ArrayList grows automatically and you don't need to specify size.
3. Items of ArrayList need to be cast to appropriate data type while retrieving.
Declaration of ArrayList
If you observe above code I haven’t mentioned any size in array list we can add all the required data there is no size limit and we will use add method to bind values to array list.